package com.zealfi.example.test.rabbitmq.config;

import com.zealfi.example.test.rabbitmq.amqp.consumer.LoanApplyMQConsumer;
import com.zealfi.example.test.rabbitmq.constant.QueueEnum;
import com.zealfi.example.test.rabbitmq.util.JsonTool;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @功能:【BindConfig 绑定队列消息】
 * @作者:代守诚
 * @日期:2018/10/19
 * @时间:15:49
 */
@Configuration
public class BindConfig extends RabbitmqConfig {

    @Bean
    public Binding bdfqBinding(@Qualifier("applyTestQueue") Queue queue, @Qualifier("bdfqChange") DirectExchange directExchange) {
        return BindingBuilder.bind(queue).to(directExchange).with(QueueEnum.BD_FENQI_APPLY_QUEUE.getRoutingKey());
    }

    /**
     * 绑定监听
     */
    @Bean
    public SimpleMessageListenerContainer applyContainer(@Qualifier("applyTestQueue") Queue applyTestQueue, LoanApplyMQConsumer loanApplyMQConsumer) {
        System.err.println("***************" + JsonTool.getFormatJsonString(loanApplyMQConsumer));
        SimpleMessageListenerContainer applyContainer = getSimpleMessageListenerContainer(loanApplyMQConsumer);
        applyContainer.setQueues(applyTestQueue);//设置监听队列的名称
        System.err.println("***************" + JsonTool.getFormatJsonString(applyContainer));
        return applyContainer;
    }
}
